package com.gao.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.gao.domain.User;
import com.gao.service.CartService;
import com.gao.service.impl.CartServiceImpl;

/**
 * Servlet implementation class CartAddNumberServlet
 */
@WebServlet("/CartAddNumberServlet")
public class CartAddNumberServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String incrementStr = request.getParameter("increment");
		String pidStr = request.getParameter("pid");
		HttpSession session = request.getSession();
		User user = (User)session.getAttribute("user");
		int uid = user.getUid();
		CartService cartService = new CartServiceImpl();
		cartService.updateNumber(Integer.parseInt(incrementStr), Integer.parseInt(pidStr), uid);
	}

}
